<template>
  <div class="user-wrapper">
    <div class="content-box">
      <span v-if="describe == 'user'|| describe =='groupLeader'" class="dan">
        <span class="bgc">{{ Dan }} → {{ experience }}</span>
      </span>
      <!-- <a href target="_blank">
        <span class="action">
          <a-icon type="question-circle-o"></a-icon>
        </span>
      </a> -->
      <notice-icon v-if="describe == 'user'|| describe =='groupLeader'" class="action" />
      <a-dropdown>
        <span class="action ant-dropdown-link user-dropdown-menu">
          <a-avatar class="avatar" size="small" :src="avatar" />
          <span class="name">{{ nickname }}</span>
        </span>
        <a-menu slot="overlay" class="user-dropdown-menu-wrapper">
          <a-menu-item key="0" disabled>
            <a-icon type="user" />
            <span>个人中心</span>
          </a-menu-item>
          <a-menu-item key="1" disabled>
            <a-icon type="setting" />
            <span>账户设置</span>
          </a-menu-item>
          <a-menu-item key="2" disabled>
            <a-icon type="setting" />
            <span>测试</span>
          </a-menu-item>
          <a-menu-divider />
          <a-menu-item key="3">
            <a-popconfirm placement="bottom" ok-text="确定" cancel-text="取消" @confirm="handleLogout">
              <template slot="title">
                <p>确定退出登录吗?</p>
              </template>
              <a href="javascript:;">
                <a-icon type="logout" />
                <span>退出登录</span>
              </a>
            </a-popconfirm>
          </a-menu-item>
        </a-menu>
      </a-dropdown>
    </div>
  </div>
</template>

<script>
import NoticeIcon from '@/components/NoticeIcon'
// import { getDaninfo } from '@/api/local/dashboard'
import { getDaninfo } from '@/api/user/dashboard'
import { mapActions, mapGetters } from 'vuex'

export default {
  name: 'UserMenu',
  components: {
    NoticeIcon
  },
  data () {
    return {
      Dan: '',
      experience: '2231',
      describe: window.describe.toString()
    }
  },
  computed: {
    ...mapGetters(['nickname', 'avatar'])
  },
  created () {
    this.getDaninfo()
    console.log('describe', window.describe)
  },
  methods: {
    ...mapActions(['Logout']),
    handleLogout () {
      this.Logout()
        .then(() => {
          setTimeout(() => {
            window.location.reload()
          }, 16)
        })
        .catch(err => {
          this.$message.error({
            title: '错误',
            description: err.message
          })
        })
      // this.$confirm({
      //   title: '提示',
      //   content: '真的要注销登录吗 ?',
      //   onOk: () => {
      //     console.log('ok')
      //     return this.Logout()
      //       .then(() => {
      //         setTimeout(() => {
      //           window.location.reload()
      //         }, 16)
      //       })
      //       .catch(err => {
      //         this.$message.error({
      //           title: '错误',
      //           description: err.message
      //         })
      //       })
      //   },
      //   onCancel () {}
      // })
    },
    getDaninfo () {
      getDaninfo()
        .then(res => {
          // console.log('getDaninfo', res.result)
          this.Dan = res.result.name
          this.experience = res.result.num
        })
        .catch(err => {
          console.log(err)
        })
    }
  }
}
</script>
<style lang="less" scoped>
.user-wrapper {
  .content-box {
    .dan {
      display: inline-block;
      font-size: 16px;
      height: 65px;
      line-height: 65px;

      .bgc {
        // display: inline-block;
        // width: 35px;
        height: 30px;
        line-height: 30px;
        padding-left: 10px;
        padding-right: 10px;
        text-align: center;
        border-radius: 5px;
        color: rgb(255, 255, 255);
        background-color: rgb(31, 168, 247) !important;
      }
    }
  }
}

@media screen and(max-width: 900px) {
  .dan {
    display: none !important;
  }

  .name {
    display: none !important;
  }
}
</style>
